<?php
/* SVN FILE: $Id: app_controller.php 4409 2007-02-02 13:20:59Z phpnut $ */
/**
 * Short description for file.
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
 * Copyright 2005-2007, Cake Software Foundation, Inc.
 *								1785 E. Sahara Avenue, Suite 490-204
 *								Las Vegas, Nevada 89104
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright		Copyright 2005-2007, Cake Software Foundation, Inc.
 * @link				http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
 * @package			cake
 * @subpackage		cake.cake
 * @since			CakePHP(tm) v 0.2.9
 * @version			$Revision: 4409 $
 * @modifiedby		$LastChangedBy: phpnut $
 * @lastmodified	$Date: 2007-02-02 07:20:59 -0600 (Fri, 02 Feb 2007) $
 * @license			http://www.opensource.org/licenses/mit-license.php The MIT License
 */
/**
 * This is a placeholder class.
 * Create the same file in app/app_controller.php
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package		cake
 * @subpackage	cake.cake
 */
class AppController extends Controller {
	
	
	
    function checkSession() {
        if (!$this->Session->check('User')) {
            $this->redirect('/users/login');
			exit();
        }
    }

    function isAdmin() {
        if($this->Session->check('User')) {
            $user = $this->Session->read('User');
            $group_id = $user['group_id'];
            if($group_id == 1) {
				return true;
            }
        }
		return false;
    }

    function userId() {
        if($this->Session->check('User')) {
            $user = $this->Session->read('User');
            return $user['id'];
        } else {
            return Null;
        }
    }

    function getUserId() {
        $u = $this->Session->read('User');
        return $u['id'];
    }
    
    function getUser() {
        if($this->Session->check('User')) {
            $user = $this->Session->read('User');
            return $user;
        } else {
            return Null;
        }
    }

	function getUsername() {
		$user = $this->getUser();
		if($user) {
			return $user['username'];
		} else {
			return "anonymous";
		}
	}

    function checkAdmin() {
        if(!$this->isAdmin()) {
            $this->redirect('/users/login');
			exit();
        }
    }
}
?>
